package cn.lix.demo.excel;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api")
public class Controller {

    @ApiOperation("解析excel文件，并按照给定模板输出")
    @PostMapping("/upload")
    public String parseSaleCheckDtl(@RequestParam(value = "startRow", defaultValue = "1") Integer startRow,
                                    @RequestParam(value = "template", defaultValue = "{A}-{B}-{E}-{AA}") String template,
                                    @RequestPart MultipartFile file) {
        List<Map<String, String>> rowValues = null;
        try {
            rowValues = ExcelParser.getRowValues(file, startRow);
            return ExcelParser.fixTemplate(template, rowValues);
        } catch (IOException e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

}
